package cn.wizzer.app.web.modules.controllers.platform.user.account;

import cn.wizzer.app.sys.modules.models.SysMsg;
import cn.wizzer.app.user.modules.models.enums.ChannelEnum;
import cn.wizzer.app.user.modules.services.account.UserRechargeService;
import cn.wizzer.app.web.commons.ulog.annotation.SLog;
import cn.wizzer.app.web.commons.utils.StringUtil;
import cn.wizzer.framework.base.Result;
import cn.wizzer.notify.WkNotifyUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;

@IocBean
@At("/platform/user/account/recharge")
public class RechargeController {
    private static final Log log = Logs.get();

    @Inject
    @Reference
    private UserRechargeService rechargeService;

    @Inject
    private WkNotifyUtil wkNotifyUtil;

    @At("")
    @Ok("beetl:/platform/user/account/recharge/index.html")
    @RequiresPermissions("user.account.recharge")
    public void index() {

    }

    @At("/add")
    @Ok("json")
    @RequiresPermissions("user.account.recharge.add")
    @SLog(tag = "手动充值", msg = "为用户:${args[0]}充值:${args[1]}")
    public Object addDo(@Param("toUser") String toUser, @Param("amount") BigDecimal amount, HttpServletRequest req) {
        rechargeService.manual(amount, toUser, StringUtil.getPlatformUid());
        return Result.success();
    }

    @At("/sure")
    @Ok("json")
    @RequiresPermissions("user.account.recharge.sure")
    @SLog(tag = "确认手动充值", msg = ":${args[0]}")
    public Object sure(@Param("id")String id,@Param("sure") Boolean sure){
        rechargeService.sure(id, sure, StringUtil.getPlatformUid());
        return Result.success();
    }

    @At
    @Ok("json:full")
    @RequiresPermissions("user.account.recharge")
    public Object data(@Param("orderNo") String orderNo,
                       @Param("searchKeyword") String searchKeyword,
                       @Param("searchDate") String[] searchDate,
                       @Param("status") Integer status,
                       @Param("channel") ChannelEnum channel,
                       @Param("pageNumber") int pageNumber,
                       @Param("pageSize") int pageSize) {
        return Result.success().addData(rechargeService.listPage(orderNo, searchKeyword, searchDate, status, channel, pageNumber, pageSize));
    }

    @At
    @Ok("json:full")
    @RequiresPermissions("user.account.recharge")
    public Object channelList() {
        return Result.success().addData(ChannelEnum.toList());
    }
}
